import instance from "./instance";
import { ElMessage } from "element-plus";
import { useCounterStore } from "../store";

// 短信接口
export function smsApi(phone) {
  return instance({
    method: "GET",
    url: "/server/login/sendsms",
    params: {
      phone,
      t: "login",
    },
  });
}

// 登录接口
export function loginApi(code, phone) {
  return instance({
    method: "post",
    url: "/server/login/dxlogin",
    // url: "/server/login/testdxlogin", //测试数据
    data: {
      code,
      phone,
      devicetype: "",
      devicecode: "",
      shangji: "",
      source: 1,
    },
  });
}
// 获取网易login信息
export function loginYunXinApi(jwt) {
  return instance({
    method: "get",
    url: `/server/login/loaduser?jwt=${jwt}`,
  });
}
// 获取网易IM的账号和token
export function iMaccountApi() {
  return instance({
    method: "get",
    url: `/server/chat/getWangYiUserImToken?jwt=${
      useCounterStore().profile.jwt
    }`,
  });
}
// 获取资料匹配身份api
// export function profileMatchApi(uid, fd) {
//   return instance({
//     method: "post",
//     url: `/server/index/pcusersinformation?uid=${uid}`,
//     data: fd,
//   });
// }
// pcusersinformation改为usersinformation[更改接口]
export function profileMatchApi(fd) {
  return instance({
    method: "post",
    url: "/server/index/usersinformation?jwt=" + useCounterStore().profile.jwt,
    data: fd,
  });
}
// /server/index/jubao  举报
export function reportMemberApi(fd) {
  return instance({
    method: "post",
    url: "/server/index/jubao?jwt=" + useCounterStore().profile.jwt,
    data: fd,
  });
}
//  撤销禁言 roomsuserspatchcancelmuteuser roomsuserspatchcancelmuteuser
export function forbiddenTalkBack(fd) {
  return instance({
    method: "post",
    url: `/server/index/roomsuserspatchcancelmuteuser?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: fd,
  });
}
// 禁言 roomsuserspatchmuteuser
export function forbiddenTalk(fd) {
  return instance({
    method: "post",
    url: `/server/index/roomsuserspatchmuteuser?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: fd,
  });
}
// 更改角色 /server/index/roomsuserspatchrole
export function modifyRole(fd) {
  return instance({
    method: "post",
    url: `/server/index/roomsuserspatchrole?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: fd,
  });
}
// 踢出房间/server/index/roomsusersdeleteremoveuser
export function ticketOut(fd) {
  return instance({
    method: "post",
    url: `/server/index/roomsusersdeleteremoveuser?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: fd,
  });
}

// 获取直播房间
export function roomLiveApi(jwt) {
  return instance({
    method: "get",
    url: `/server/live/getmyliveroom?jwt=${jwt}&cat=${2}&status=${1}`,
  });
}
export function getuserinfo({ userid = "", look = 1 }) {
  return instance({
    method: "get",
    url: "/server/index/getuserinfo",
    params: {
      userid,
      jwt: useCounterStore().profile.jwt,
      look,
    },
  });
}
export function getIsFollow({ followuid, str = "follow" }) {
  return instance({
    method: "get",
    url: "/server/index/" + str,
    params: {
      followuid,
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// 弹出信息
export function $TipMessage(message, type) {
  ElMessage({
    message,
    type,
  });
}
// pk
// 在线邀请列表
export function onLineListApi({ roomid, isfollow, page, limit }) {
  return instance({
    method: "get",
    url: "/server/index/videoonlineroomlist",
    params: {
      jwt: useCounterStore().profile.jwt,
      roomid,
      isfollow,
      page,
      limit,
    },
  });
}
// 创建pk房间
export function createPkRoomApi({ room_name, host_user_uuid }) {
  const formData = new FormData();
  let options = {
    room_uuid: new Date().getTime().toString().slice(-7),
    room_name,
    host_user_uuid,
  };
  Object.keys(options).forEach((v) => {
    formData.append(v, options[v]);
  });
  return instance({
    method: "post",
    url: `/server/index/roomspostcreatepk?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}
// 第一次是加入  /server/index/videopkjoinpkteam -去掉【pkid，invited_roomid】
// 第一次是邀请  /server/index/videopkjoinpkteam -添加【pkid，invited_roomid】
export function invitLiveApi({ type, roomid, order, pkid, invited_roomid }) {
  const formData = new FormData();
  let options = {
    type,
    roomid,
    order,
    pkid,
    invited_roomid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videopkjoinpkteam?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}

// /server/index/videopkhandleinvite 接受or拒绝 1同意2拒绝
export function rejectAndAgainApi({ roomid, pkid, status }) {
  const formData = new FormData();
  let options = {
    roomid,
    pkid,
    status,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videopkhandleinvite?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
// https://app.xinxin128.com/server/live/testDelPkData 清空缓存
export function delCash() {
  return instance({
    method: "get",
    url: "/server/live/testDelPkData",
  });
}

export function enablePkApi({ pkid, time }) {
  const formData = new FormData();
  let options = {
    pkid,
    time,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videopkstart?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}
// /server/index/videoapplycontactlist 邀请上麦列表

export function invitMikeApi({ roomid }) {
  const formData = new FormData();
  let options = {
    roomid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videoapplycontactlist?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
// server/index/videoinvitecontact 邀请 【一般主播邀请观众连麦】
export function invitAudience({ roomid, userid }) {
  const formData = new FormData();
  let options = {
    roomid,
    userid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videoinvitecontact?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
// 模拟客户端的

// /server/index/videocontactuserlist 连麦管理
export function manageMikeApi({ roomid }) {
  const formData = new FormData();
  let options = {
    roomid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videocontactuserlist?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
// videohandlecontact 处理连麦申请 同意or拒绝
export function handlerLinkMikeApi({ roomid, status, userid }) {
  const formData = new FormData();
  let options = {
    roomid,
    status,
    userid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videohandlecontact?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
//videocontactstop 踢出  | 挂断-》需要uid，下麦不需要
export function offMikeApi({ roomid, userid }) {
  const formData = new FormData();
  let options = {
    roomid,
    userid,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/videocontactstop?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}

// 举报
export function reportMember({ type = 1, touid, msg, img }) {
  const formData = new FormData();
  let options = {
    type,
    touid,
    msg,
    img,
  };
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/index/jubao?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}

// 获取随机名称 /server/index/getrandomname
export function randomNameApi() {
  const formData = new FormData();
  formData.append("userid", useCounterStore().profile.user.id);
  return instance({
    method: "post",
    url: "/server/index/getrandomname",
    data: formData,
  });
}
// /server/login/createuid 创建子账号
export function createSonAccountApi({ optype, sex, nickname, headimgurl }) {
  const formData = new FormData();
  let options = {
    optype,
    sex,
    nickname,
    headimgurl,
  };
  console.log("options", options);
  Object.keys(options).forEach((v) => {
    if (options[v]) {
      formData.append(v, options[v]);
    }
  });
  return instance({
    method: "post",
    url: `/server/login/createuid?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}

// head api 工会列表
export function getUnionRooms() {
  return instance({
    method: "get",
    url: "/server/live/getfamilyroomlist",
    params: {
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// 账号列表
// export function getUnionAccount({ page, limit, id }) {
//   return instance({
//     method: "get",
//     url: "/server/index/familyuserlist",
//     params: {
//       jwt: useCounterStore().profile.jwt,
//       page,
//       limit,
//       id, //家族id
//     },
//   });
// }
//账号列表 更改 接口
export function getUnionAccount() {
  return instance({
    method: "post",
    url: "/server/login/useridlist",
    params: {
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// 礼物列表
export function giftListApi(fenlei) {
  return instance({
    method: "get",
    url: "/server/live/giftlist",
    params: {
      uid: useCounterStore().profile.user.id,
      fenlei: fenlei,
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// 礼物列表中的背包列表
export function getmybeibaoApi() {
  return instance({
    method: "get",
    url: "/server/live/getmybeibao",
    params: {
      uid: useCounterStore().profile.user.id,
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// 系统消息  /server/index/getststemmsg
export function getststemmsgApi({ page, limit }) {
  return instance({
    method: "get",
    url: "/server/index/getststemmsg",
    params: {
      page,
      limit,
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// /server/chat/getuserStatusbyids 消息列表通过拼id字符给后端
export function msgByCookiApi({ uids }) {
  const formData = new FormData();
  formData.append("uids", uids);
  return instance({
    method: "post",
    url: `/server/chat/getuserStatusbyids?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}

// /server/login/uidnewlogin 子账号登录
export function sonAccountApi(userid) {
  const formData = new FormData();
  formData.append("userid", userid);
  return instance({
    method: "post",
    url: "/server/login/uidnewlogin",
    data: formData,
  });
}

// /server/index/getfangwenlist
export function whoLookMeApi({ page, limit, source }) {
  return instance({
    method: "get",
    url: "/server/index/getfangwenlist",
    params: {
      page,
      limit,
      jwt: useCounterStore().profile.jwt,
      source,
    },
  });
}
// /server/chat/friendapplylist
export function friendAskListApi({ page, limit }) {
  return instance({
    method: "get",
    url: "/server/chat/friendapplylist",
    params: {
      page,
      limit,
      jwt: useCounterStore().profile.jwt,
      userid: useCounterStore().profile.user.id,
    },
  });
}
// /server/index/getfastphraselist
export function quickReplyListApi({ page, limit, roomid }) {
  return instance({
    method: "get",
    url: "/server/index/getfastphraselist",
    params: {
      jwt: useCounterStore().profile.jwt,
      roomid,
      page,
      limit,
    },
  });
}
// addfastphrase
export function addAuickReplyApi(phrase, roomid) {
  const formData = new FormData();
  formData.append("phrase", phrase);
  formData.append("roomid", roomid);
  return instance({
    method: "post",
    url: "/server/index/addfastphrase",
    data: formData,
  });
}
// /server/index/delfastphrase
export function delAuickReplyApi(id) {
  const formData = new FormData();
  formData.append("id", id);
  formData.append("roomid", useCounterStore().profile.user.roomid);
  return instance({
    method: "post",
    url: "/server/index/delfastphrase",
    data: formData,
  });
}
export function getPaihang({ type, type1, page, limit }) {
  return instance({
    method: "get",
    url: "/server/index/getpaihang",
    params: {
      roomid: useCounterStore().profile.user.roomid,
      type,
      type1,
      page,
      limit,
      jwt: useCounterStore().profile.jwt,
    },
  });
}
// /server/index/roomsusersadminlist
export function adminlist(room_archive_id, room_uuid) {
  const formData = new FormData();
  formData.append("room_archive_id", room_archive_id);
  formData.append("room_uuid", room_uuid);
  return instance({
    method: "post",
    url: `/server/index/roomsusersadminlist?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
export function laheilist(room_archive_id, page_number, page_size) {
  const formData = new FormData();
  formData.append("room_archive_id", room_archive_id);
  formData.append("page_number", page_number);
  formData.append("page_size", page_size);
  return instance({
    method: "post",
    url: `/server/index/roomsgetblacklist?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}
export function jinyanlist(room_archive_id, page_number, page_size) {
  const formData = new FormData();
  formData.append("room_archive_id", room_archive_id);
  formData.append("chat", true);
  formData.append("video", false);
  formData.append("audio", false);
  formData.append("page_number", page_number);
  formData.append("page_size", page_size);
  return instance({
    method: "post",
    url: `/server/index/roomsgetmutelist?jwt=${useCounterStore().profile.jwt}`,
    data: formData,
  });
}
// 取消拉黑 /server/index/roomspatchremoveblacklist
export function cancelLahei(room_archive_id, user_uuid) {
  const formData = new FormData();
  formData.append("room_archive_id", room_archive_id);
  formData.append("user_uuid", user_uuid);
  return instance({
    method: "post",
    url: `/server/index/roomspatchremoveblacklist?jwt=${
      useCounterStore().profile.jwt
    }`,
    data: formData,
  });
}
